package com.tanhua.server.controller;

import com.tanhua.domain.db.Answer;
import com.tanhua.server.serivce.SoulService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 测试灵魂的控制器
 */
@RestController
@RequestMapping("/testSoul")
@Slf4j
public class TestSoulController {

    @Autowired
    private SoulService soulService;

    /**
     * 接口名称：测灵魂-问卷列表
     * 接口路径：GET/testSoul
     */
    @GetMapping()
    public ResponseEntity<Object> soulQuestionnaireList(){
        log.info("测灵魂-问卷列表");
        return soulService.soulQuestionnaireList();
    }

    /**
     * 接口名称：测灵魂-提交问卷
     * 接口路径：POST/testSoul
     */
    @PostMapping()
    public ResponseEntity<Object> answerQuestionnaire(@RequestBody Map<String, List<Answer>> paramMap){
        log.info("测灵魂-提交问卷");
        List<Answer> answerList = paramMap.get("answers");
        return soulService.answerQuestionnaire(answerList);
    }

    /**
     * 接口名称：测灵魂-查看结果
     * 接口路径：GET/testSoul/report/:id
     */
    @GetMapping("/report/{id}")
    public ResponseEntity<Object> findQuestionnaireReport(@PathVariable("id") Long reportId){
        log.info("测灵魂-查看结果");
        return soulService.findQuestionnaireReport(reportId);
    }
}
